home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Code Resources / NeXT CDEF / NeXT CDEF.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  18.5 KB  |  607 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.         NeXT CDEF.c++
  4.         
  5.         Another CDEF implementing NeXT-like features...
  6.         
  7.         by Hiep Dam, 3G Software
  8.         Copyright (C) 1994 by Hiep Dam
  9.         Feel free to use the CDEF in your own projects or to use the source
  10.         code as a starting point for your own cdefs. I only ask you give me
  11.         tiny credits somewhere in your application and/or send me a copy...
  12.         
  13.         Contacting the author:
  14.         America Online: StarLabs
  15.         Delphi:         StarLabs
  16.         Internet:       starlabs@aol.com, starlabs@delphi.com
  17.         
  18.         Last update: May 4, 1994
  19.         
  20.         ••• IMPORTANT: Requires COLOR QUICKDRAW and SYSTEM 7!!! •••
  21.                        Does NO error-checking for the above whatsoever....
  22.  
  23. */
  24.  
  25. // ----------------------------------------------------------------------
  26.  
  27. // Note:
  28. //        1) Whenever you see ">> 1" in the code, that means "/ 2". It's a quick
  29. //           shortcut to divide by 2. I use it so I don't have to include the
  30. //           math library.
  31.  
  32. // NeXT CDEF variation codes:
  33. // • stdBtnProc, sysFontBtnProc, geneva9BtnProc:
  34. //        All text-only btn procs. No special handling required.
  35. //        Control value, max, & min ignored.
  36. // • cicnBtnProc:
  37. //        draws simple color icon. No text drawn (it's ignored).
  38. //        Control value holds the rsrc id of the color icon to draw.
  39. //        Control max & min ignored.
  40. // • inRectProc, outRectProc:
  41. //        Just frames, similar to the button frames. Doesn't respond to clicks.
  42. //        Use mainly as dressing...
  43.  
  44. // Some important things I learned (the HARD way!):
  45. // • In the ctrlMin and ctrlMax fields, always make sure ctrlMin is less
  46. //   than ctrlMax!! This is less obvious when you use these fields to hold
  47. //   private data (such as id's of cicn's) but the Control Manager DOES
  48. //   do range-checking, and you will get strangely-working buttons if
  49. //   ctrlMin is greater than ctrlMax.
  50. // • Similarly, make sure that ctrlValue is within the range specified by
  51. //   ctrlMin and ctrlMax. Again, the Control Manager does do range-checking,
  52. //   and will coerce the ctrlValue field to the appropriate value if it's
  53. //   greater than ctrlMax or less than ctrlMin.
  54. //   I had wanted the ctrlValue to hold either 0 or 1, and if it was 0 the
  55. //   CDEF was to use the value in the ctrlMin field (let's say 128) to draw
  56. //   the icon. If the value was 1, the CDEF was to use the value in the
  57. //   ctrlMax field (129, for example). The problem, however, was that 0 and 1
  58. //   was out of range specified by the ctrlMin & ctrlMax fields, which were
  59. //   128 and 129. So this didn't work. A fix: just put the id itself in the
  60. //   ctrlValue field, instead of 0 or 1. So it might either contain 128 or 129.
  61.  
  62. // Version Control:
  63. //    Version 1.1,    Feb 18 1993
  64. //        Added inRectProc, outRectProc
  65.  
  66. // ----------------------------------------------------------------------
  67.  
  68. typedef enum CDEFconstants {
  69.     // NeXT CDEF variation codes - yeah there's a lot!
  70.     stdBtnProc        = 0,            // Std btn variation: use window font
  71.     sysFontBtnProc    = 1,            // Uses System font
  72.     geneva9BtnProc    = 2,            // Uses Geneva 9
  73.     cicnBtnProc        = 3,            // Simple CICN btn
  74.     checkBxBtnProc  = 4,
  75.     radioBxBtnProc  = 5,
  76.     popupBtnProc    = 6,            // Uses window font
  77.     geneva9PopupProc= 7,            // Use geneva 9
  78.     inRectProc        = 10,
  79.     outRectProc        = 11,
  80.     sysFontCheckBxBtnProc = 12,
  81.     geneva9CheckBxBtnProc = 13,
  82.     sysFontRadioBxBtnProc = 14,
  83.     geneva9RadioBxBtnProc = 15,
  84.  
  85.     // NeXT CDEF part codes
  86.     unhilite     = 0,
  87.     btnHilite    = inButton,
  88.     btnDisabled  = 255,
  89.     btnCheckBox  = inCheckBox,
  90.  
  91.     btnOff         = 0,
  92.     btnOn         = 1,
  93.  
  94.     checkBxHt    = 12,            // Height of check box/radio button
  95.     checkBxWd    = 12,            // Width
  96.  
  97.     centerJustification = 0,
  98.     leftJustification   = 1,
  99.     rightJustification  = 2,
  100.  
  101.     leftPadding  = 4,            // Offset to left when drawing text in checkboxes
  102.     rightPadding = 4,
  103.     vertOffset   = -1,            // Pretty-printing for drawing text in buttons
  104.  
  105.     kBlack         = 0,            // Some RGBColor constants
  106.     kWhite         = 65535,
  107.     kLtGray         = 56797,       // light (56797) or darker (48059)
  108.     kDkGray         = 17467        // 17467 (lighter) or darker (8738)
  109. };
  110.  
  111. // MDEFColors struct.
  112. // Used for keeping track of menu colors, from function to function,
  113. // since we aren't allowed to have globals (though we can if we want
  114. // to, using the A4 register, but that's too skanky for me).
  115.  
  116. typedef struct CDEFcolors {
  117.     struct RGBColor black;
  118.     struct RGBColor white;
  119.     struct RGBColor ltGray;
  120.     struct RGBColor dkGray;
  121. };
  122.  
  123. // ----------------------------------------------------------------------
  124.  
  125. pascal OSErr PlotCIconHandle(Rect *theRect, short alignment, short transform,
  126.         CIconHandle theIcon) = { 0x303C, 0x061F, 0xABC9 };
  127.  
  128. void FillInColor(RGBColor *theColor, unsigned short r, unsigned short g, unsigned short b);
  129. void InitCDEFColors(CDEFcolors *theColors);
  130. void DrawControl(ControlHandle theControl, short variation, long part);
  131. short TestControl(ControlHandle theControl, short variation, long location);
  132. void CalcRgnControl(ControlHandle theControl, long ref);
  133. void CalcRgnControl32Bit(ControlHandle theControl, long ref);
  134.  
  135. // ----------------------------------------------------------------------
  136.  
  137. pascal long main(short variation, ControlHandle theControl, short msg, long parameter) {
  138.     long returnVal = 0;
  139.  
  140.     switch(msg) {
  141.         case initCntl: {
  142.             // For this control def, we don't need to allocate any private
  143.             // data or do any special initialization, so don't do anything
  144.             // here.
  145.         } break;
  146.         
  147.         case drawCntl: {
  148.             DrawControl(theControl, variation, parameter);
  149.         } break;
  150.         
  151.         case testCntl: {
  152.             returnVal = TestControl(theControl, variation, parameter);
  153.         } break;
  154.         
  155.         case calcCRgns: {
  156.             // We receive this msg if running in Sys 6 or Sys 7 with 24-bit
  157.             // addressing on.
  158.             CalcRgnControl(theControl, parameter);
  159.         } break;
  160.         
  161.         case calcCntlRgn: {
  162.             // We receive this msg if running on Sys 7 with 32-bit
  163.             // addressing on. Gotta be 32-bit clean!
  164.             CalcRgnControl32Bit(theControl, parameter);
  165.         } break;
  166.         
  167.         case dispCntl: {
  168.             // If you allocated any private data previously, this is
  169.             // where you de-allocate it.
  170.             // Since we didn't allocate anything, so do nothing.
  171.         } break;
  172.     } // END switch
  173.     
  174.     return(returnVal);
  175. } // END main
  176.  
  177. // ----------------------------------------------------------------------
  178.  
  179. void CenterRect(Rect *innerRect, Rect *outerRect) {
  180.     short hDiff = ((outerRect->right - outerRect->left) - (innerRect->right - innerRect->left)) >> 1;
  181.     short vDiff = ((outerRect->bottom - outerRect->top) - (innerRect->bottom - innerRect->top)) >> 1;
  182.     innerRect->left = outerRect->left + hDiff;
  183.     innerRect->right = outerRect->right - hDiff;
  184.     innerRect->top = outerRect->top + vDiff;
  185.     innerRect->bottom = outerRect->bottom - vDiff;
  186. }
  187.  
  188. // ----------------------------------------------------------------------
  189.  
  190. void DrawCICN(short iconID, short hiliteStatus, Rect *cdefRect) {
  191.     CIconHandle controlIcon = GetCIcon(iconID);
  192.     if (controlIcon == nil)
  193.         return;
  194.  
  195.     Rect iconRect = (*controlIcon)->iconPMap.bounds;
  196.     CenterRect(&iconRect, cdefRect);
  197.  
  198.     if (hiliteStatus == btnHilite)
  199.         OffsetRect(&iconRect, 1, 1);
  200.  
  201.     if (hiliteStatus == btnDisabled)
  202.         // atNone == 0x00
  203.         // ttDisabled == 0x0001
  204.         PlotCIconHandle(&iconRect, 0x00, 0x0001, controlIcon);
  205.     else
  206.         PlotCIcon(&iconRect, controlIcon);
  207.     DisposeCIcon(controlIcon);
  208. } // END DrawCICN
  209.  
  210. // ----------------------------------------------------------------------
  211.  
  212. void DrawColorIcon(ControlHandle theControl, short hiliteStatus, Rect *cdefRect) {
  213.     short iconID = (*theControl)->contrlValue;
  214.     DrawCICN(iconID, hiliteStatus, cdefRect);
  215. } // END DrawColorIcon
  216.  
  217. // ----------------------------------------------------------------------
  218.  
  219. void DrawControlText(ControlHandle theControl, short variation, short hiliteStatus,
  220.                         Rect *cdefRect, CDEFcolors *cdefColors) {
  221.     short offsetH, offsetV, halfFontDiff, halfCdefDiff;
  222.     short justification = centerJustification;
  223.  
  224.     short saveFont = (*theControl)->contrlOwner->txFont;
  225.     short saveSize = (*theControl)->contrlOwner->txSize;
  226.     short saveFace = (*theControl)->contrlOwner->txFace;
  227.     short saveMode = (*theControl)->contrlOwner->txMode;
  228.  
  229.     switch(variation) {
  230.         case sysFontBtnProc:
  231.         case sysFontCheckBxBtnProc:
  232.         case sysFontRadioBxBtnProc:
  233.             TextFont(systemFont);
  234.             TextSize(12);
  235.             TextFace(0);    // plain
  236.             if (variation != sysFontBtnProc)
  237.                 justification = leftJustification;
  238.         break;
  239.         
  240.         case geneva9BtnProc:
  241.         case geneva9CheckBxBtnProc:
  242.         case geneva9RadioBxBtnProc:
  243.             TextFont(geneva);
  244.             TextSize(9);
  245.             TextFace(0);
  246.             if (variation != geneva9BtnProc)
  247.                 justification = leftJustification;
  248.         break;
  249.         
  250.         case stdBtnProc:
  251.         case checkBxBtnProc:
  252.         case radioBxBtnProc:
  253.             // Use window font & size, so do nothing
  254.             if (variation != stdBtnProc)
  255.                 justification = leftJustification;
  256.         break;
  257.  
  258.         case popupBtnProc:
  259.             justification = leftJustification;
  260.         break;
  261.         
  262.         case geneva9PopupProc:
  263.             TextFont(geneva);
  264.             TextSize(9);
  265.             TextFace(0);
  266.             justification = leftJustification;
  267.         break;
  268.  
  269.         case inRectProc:
  270.         case outRectProc:
  271.             justification = leftJustification;
  272.         break;
  273.         
  274.         default:
  275.             justification = leftJustification;
  276.         break;
  277.     } // END switch
  278.  
  279.     FontInfo theInfo;
  280.     GetFontInfo(&theInfo);
  281.  
  282.     halfFontDiff = theInfo.ascent >> 1;
  283.     halfCdefDiff = (cdefRect->bottom - cdefRect->top) >> 1;
  284.     offsetV = halfCdefDiff - halfFontDiff;
  285.  
  286.     if (justification == centerJustification) {
  287.         short strWidth = StringWidth((*theControl)->contrlTitle);
  288.         halfFontDiff = strWidth >> 1;
  289.         halfCdefDiff = (cdefRect->right - cdefRect->left) >> 1;
  290.         offsetH = halfCdefDiff - halfFontDiff;
  291.     }
  292.     else {
  293.         offsetH = leftPadding;
  294.     }
  295.     
  296.     RGBForeColor(&cdefColors->black);
  297.     MoveTo(cdefRect->left + offsetH, cdefRect->bottom - offsetV + vertOffset);
  298.     if (hiliteStatus == btnHilite)
  299.         Move(1, 1);
  300.     if (hiliteStatus == btnDisabled)
  301.         TextMode(grayishTextOr);
  302.     DrawString((*theControl)->contrlTitle);
  303.     
  304.     TextFont(saveFont);
  305.     TextSize(saveSize);
  306.     TextFace(saveFace);
  307.     TextMode(saveMode);
  308. } // END DrawControlText
  309.  
  310. // ----------------------------------------------------------------------
  311.  
  312. void Draw3DRadio(ControlHandle theControl, short hiliteStatus, Rect *radioRect,
  313.                 CDEFcolors *cdefColors) {
  314.     Rect radioR = *radioRect;
  315.     PenSize(2, 2);
  316.  
  317.     // Draw highlight
  318.     if (hiliteStatus == btnCheckBox)
  319.         RGBForeColor(&cdefColors->white);
  320.     else
  321.         RGBForeColor(&cdefColors->dkGray);
  322.     FrameArc(&radioR, 45, 180);
  323.  
  324.     // Draw shadow
  325.     if (hiliteStatus == btnCheckBox)
  326.         RGBForeColor(&cdefColors->dkGray);
  327.     else
  328.         RGBForeColor(&cdefColors->white);
  329.     FrameArc(&radioR, 225, 180);
  330.  
  331.     // Erase circle inside highlight & shadow
  332.     RGBForeColor(&cdefColors->ltGray);
  333.     InsetRect(&radioR, 2, 2);
  334.     PaintOval(&radioR);
  335.  
  336.     // If button on, show dot
  337.     if ((*theControl)->contrlValue == 1) {
  338.         InsetRect(&radioR, 1, 1);
  339.         PenSize(1, 1);
  340.         RGBForeColor(&cdefColors->dkGray);
  341.         PaintOval(&radioR);
  342.     }
  343. } // END Draw3DRadio
  344.  
  345. // ----------------------------------------------------------------------
  346.  
  347. void Draw3DButton(short hiliteStatus, Rect *cdefRect, CDEFcolors *cdefColors) {
  348.     RGBBackColor(&cdefColors->ltGray);
  349.     EraseRect(cdefRect);
  350.     
  351.     if (hiliteStatus == btnHilite || hiliteStatus == btnCheckBox)
  352.         RGBForeColor(&cdefColors->dkGray);
  353.     else
  354.         RGBForeColor(&cdefColors->white);
  355.     // Draw top edge
  356.     MoveTo(cdefRect->left, cdefRect->top);
  357.     LineTo(cdefRect->right - 1, cdefRect->top);
  358.     MoveTo(cdefRect->left, cdefRect->top + 1);
  359.     LineTo(cdefRect->right - 2, cdefRect->top + 1);
  360.     // Draw left edge
  361.     MoveTo(cdefRect->left, cdefRect->top + 2);
  362.     LineTo(cdefRect->left, cdefRect->bottom);
  363.     MoveTo(cdefRect->left + 1, cdefRect->top + 2);
  364.     LineTo(cdefRect->left + 1, cdefRect->bottom - 1);
  365.     if (hiliteStatus == btnHilite || hiliteStatus == btnCheckBox)
  366.         RGBForeColor(&cdefColors->white);
  367.     else
  368.         RGBForeColor(&cdefColors->dkGray);
  369.     // Draw right edge
  370.     MoveTo(cdefRect->right, cdefRect->top);
  371.     LineTo(cdefRect->right, cdefRect->bottom);
  372.     MoveTo(cdefRect->right - 1, cdefRect->top + 1);
  373.     LineTo(cdefRect->right - 1, cdefRect->bottom);
  374.     // Draw bottom edge
  375.     MoveTo(cdefRect->right - 2, cdefRect->bottom);
  376.     LineTo(cdefRect->left + 1, cdefRect->bottom);
  377.     MoveTo(cdefRect->right - 2, cdefRect->bottom - 1);
  378.     LineTo(cdefRect->left + 2, cdefRect->bottom - 1);
  379. } // END Draw3DButton
  380.  
  381. // ----------------------------------------------------------------------
  382.  
  383. void DrawPopupButton(short hiliteStatus, Rect *cdefRect, CDEFcolors *cdefColors) {
  384.     // First, draw shadow
  385.     Rect innerRect = *cdefRect;
  386.     OffsetRect(&innerRect, 2, 2);
  387.     RGBBackColor(&cdefColors->dkGray);
  388.     EraseRect(&innerRect);
  389.     OffsetRect(&innerRect, -2, -2);
  390.     
  391.     RGBBackColor(&cdefColors->ltGray);
  392.     EraseRect(cdefRect);
  393.  
  394.     RGBForeColor(&cdefColors->black);
  395.     FrameRect(cdefRect);
  396.  
  397.     InsetRect(&innerRect, 1, 1);
  398.     innerRect.right--; innerRect.bottom--;
  399.  
  400.     RGBForeColor(&cdefColors->white);
  401.     // Draw top edge
  402.     MoveTo(innerRect.left, innerRect.top);
  403.     LineTo(innerRect.right - 1, innerRect.top);
  404.     // Draw left edge
  405.     MoveTo(innerRect.left, innerRect.top);
  406.     LineTo(innerRect.left, innerRect.bottom);
  407.  
  408.     RGBForeColor(&cdefColors->dkGray);
  409.     // Draw right edge
  410.     MoveTo(innerRect.right, innerRect.top);
  411.     LineTo(innerRect.right, innerRect.bottom);
  412.     // Draw bottom edge
  413.     MoveTo(innerRect.left + 1, innerRect.bottom);
  414.     LineTo(innerRect.right, innerRect.bottom);
  415. } // END DrawPopupButton
  416.  
  417. // ----------------------------------------------------------------------
  418.  
  419. void DrawCheckBox(ControlHandle theControl, short variation, short hiliteStatus,
  420.                 Rect *cdefRect, CDEFcolors *cdefColors) {
  421.     Rect checkBxRect = *cdefRect;
  422.     checkBxRect.bottom = cdefRect->top + checkBxHt;
  423.     CenterRect(&checkBxRect, cdefRect);
  424.     checkBxRect.right = checkBxRect.left + checkBxWd;
  425.     
  426.     switch(variation) {
  427.         case checkBxBtnProc:
  428.         case sysFontCheckBxBtnProc:
  429.         case geneva9CheckBxBtnProc:
  430.             Draw3DButton(hiliteStatus, &checkBxRect, cdefColors);
  431.             if ((*theControl)->contrlValue == 1) {
  432.                 InsetRect(&checkBxRect, 3, 3);
  433.                 checkBxRect.right--;
  434.                 checkBxRect.bottom--;
  435.                 PenNormal();
  436.                 RGBForeColor(&cdefColors->black);
  437.                 MoveTo(checkBxRect.left, checkBxRect.top + 1);
  438.                 LineTo(checkBxRect.right, checkBxRect.bottom + 1);
  439.                 MoveTo(checkBxRect.right, checkBxRect.top + 1);
  440.                 LineTo(checkBxRect.left, checkBxRect.bottom + 1);
  441.                 RGBForeColor(&cdefColors->white);
  442.                 MoveTo(checkBxRect.right, checkBxRect.top - 1);
  443.                 LineTo(checkBxRect.left, checkBxRect.bottom - 1);
  444.                 MoveTo(checkBxRect.left, checkBxRect.top - 1);
  445.                 LineTo(checkBxRect.right, checkBxRect.bottom - 1);
  446.                 RGBForeColor(&cdefColors->ltGray);
  447.                 MoveTo(checkBxRect.left, checkBxRect.top);
  448.                 LineTo(checkBxRect.right, checkBxRect.bottom);
  449.                 MoveTo(checkBxRect.right, checkBxRect.top);
  450.                 LineTo(checkBxRect.left, checkBxRect.bottom);
  451.             }
  452.         break;
  453.         
  454.         case radioBxBtnProc:
  455.         case sysFontRadioBxBtnProc:
  456.         case geneva9RadioBxBtnProc:
  457.             Draw3DRadio(theControl, hiliteStatus, &checkBxRect, cdefColors);
  458.         break;
  459.     } // END switch
  460. } // END DrawCheckBox
  461.  
  462. // ----------------------------------------------------------------------
  463.  
  464. void DrawBoxBounds(ControlHandle theControl, short variation, Rect *cdefRect, CDEFcolors *cdefColors) {
  465.     short rectStyle;
  466.  
  467.     if (variation == inRectProc)
  468.         rectStyle = btnHilite;
  469.     else if (variation == outRectProc)
  470.         rectStyle = unhilite;
  471.         
  472.     Draw3DButton(rectStyle, cdefRect, cdefColors);
  473. } // END DrawBoxBounds
  474.  
  475. // ----------------------------------------------------------------------
  476.  
  477. void DrawControl(ControlHandle theControl, short variation, long part) {
  478.     short hiliteStatus = (*theControl)->contrlHilite;
  479.     Rect cdefRect = (*theControl)->contrlRect;
  480.     PenState savePen;
  481.     RGBColor foreSave, backSave;
  482.     GetForeColor(&foreSave);
  483.     GetBackColor(&backSave);
  484.     CDEFcolors cdefColors;
  485.     InitCDEFColors(&cdefColors);
  486.     GetPenState(&savePen);
  487.     PenNormal();
  488.     
  489.     switch(variation) {
  490.         case stdBtnProc:
  491.         case sysFontBtnProc:
  492.         case geneva9BtnProc:
  493.             Draw3DButton(hiliteStatus, &cdefRect, &cdefColors);
  494.             DrawControlText(theControl, variation, hiliteStatus, &cdefRect, &cdefColors);
  495.         break;
  496.         
  497.         case cicnBtnProc:
  498.             Draw3DButton(hiliteStatus, &cdefRect, &cdefColors);
  499.             DrawColorIcon(theControl, hiliteStatus, &cdefRect);
  500.         break;
  501.         
  502.         case checkBxBtnProc:
  503.         case radioBxBtnProc:
  504.         case sysFontCheckBxBtnProc:
  505.         case sysFontRadioBxBtnProc:
  506.         case geneva9CheckBxBtnProc:
  507.         case geneva9RadioBxBtnProc:
  508.             DrawCheckBox(theControl, variation, hiliteStatus, &cdefRect, &cdefColors);
  509.             Rect checkBxRect = cdefRect;
  510.             checkBxRect.left += checkBxWd;
  511.             DrawControlText(theControl, variation, hiliteStatus, &checkBxRect, &cdefColors);
  512.         break;
  513.         
  514.         case inRectProc:
  515.         case outRectProc:
  516.             DrawBoxBounds(theControl, variation, &cdefRect, &cdefColors);
  517.         break;
  518.  
  519.         case popupBtnProc:
  520.         case geneva9PopupProc:
  521.             DrawPopupButton(hiliteStatus, &cdefRect, &cdefColors);
  522.             Rect textRect = cdefRect;
  523.             InsetRect(&textRect, 2, 2);
  524.             DrawControlText(theControl, variation, hiliteStatus, &textRect, &cdefColors);
  525.     } // END switch
  526.  
  527.     RGBForeColor(&foreSave);
  528.     RGBBackColor(&backSave);
  529.     SetPenState(&savePen);
  530. } // END DrawControl
  531.  
  532. // ----------------------------------------------------------------------
  533.  
  534. short TestControl(ControlHandle theControl, short variation, long location) {
  535.     Point pt;
  536.  
  537.     pt.v = HiWord(location); 
  538.     pt.h = LoWord(location);
  539.  
  540.     if (PtInRect(pt, &((*theControl)->contrlRect))) {
  541.         switch(variation) {
  542.             case checkBxBtnProc:
  543.             case radioBxBtnProc:
  544.             case sysFontCheckBxBtnProc:
  545.             case sysFontRadioBxBtnProc:
  546.             case geneva9CheckBxBtnProc:
  547.             case geneva9RadioBxBtnProc:
  548.                 return(btnCheckBox);
  549.             break;
  550.             
  551.             case inRectProc:
  552.             case outRectProc:
  553.             case geneva9PopupProc:
  554.                 return(unhilite);
  555.             break;
  556.  
  557.             case popupBtnProc:
  558.                 return(unhilite);
  559.             break;
  560.  
  561.             default:
  562.                 return(btnHilite);
  563.             break;
  564.         } // END switch
  565.     }
  566.     else {
  567.         return(unhilite);
  568.     }
  569. } // END TestControl
  570.  
  571. // ----------------------------------------------------------------------
  572.  
  573. void CalcRgnControl(ControlHandle theControl, long ref) {
  574.     RgnHandle theRgn;
  575.     theRgn = (RgnHandle)ref;
  576.     theRgn = (RgnHandle)((long)theRgn & 0x7FFFFFFF);    // Clear high bit
  577.     RectRgn(theRgn, &((*theControl)->contrlRect));
  578. } // END CalcRgnControl
  579.  
  580.  
  581. // Let's be 32-bit clean, now!
  582. void CalcRgnControl32Bit(ControlHandle theControl, long ref) {
  583.     RectRgn((RgnHandle)ref, &((*theControl)->contrlRect));
  584. } // END CalcRgnControl32Bit
  585.  
  586. // ----------------------------------------------------------------------
  587.  
  588. // FillInColor.
  589. // If you use RGBColors, no doubt you'll be using some function similar to this.
  590. // Now why didn't Apple include a function like this? Less overhead, I guess.
  591.  
  592. void FillInColor(RGBColor *theColor, unsigned short r, unsigned short g, unsigned short b) {
  593.     theColor->red   = r;
  594.     theColor->green = g;
  595.     theColor->blue  = b;
  596. } // END FillInColor
  597.  
  598. // ----------------------------------------------------------------------
  599.  
  600. void InitCDEFColors(CDEFcolors *theColors) {
  601.     FillInColor(&theColors->white, kWhite, kWhite, kWhite);
  602.     FillInColor(&theColors->black, kBlack, kBlack, kBlack);
  603.     FillInColor(&theColors->ltGray, kLtGray, kLtGray, kLtGray);
  604.     FillInColor(&theColors->dkGray, kDkGray, kDkGray, kDkGray);
  605. } // END InitCDEFColors
  606.  
  607. // ----------------------------------------------------------------------